package com.lms.demo.fileservice.handler;

import com.lms.demo.fileservice.exception.GeneralException;
import com.lms.demo.fileservice.util.ResponseResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: 李孟帅
 * @CreateTime: 2020-12-24 16:54
 * @Description:
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    private static final Logger LOGGER=LoggerFactory.getLogger(GlobalExceptionHandler.class);
    private static final String LINE = "==========================================》{}";

    /**
    * @Author 李孟帅
    * @Date 2020/12/24 16:55
    * @Description 系统异常处理
    */
    @ExceptionHandler({Exception.class})
    @ResponseBody
    public ResponseResult<?> exceptionHandler(HttpServletRequest request, Exception e){
        String uri = request.getRequestURI();
        LOGGER.error(uri+",异常" + LINE, e.getMessage());
        e.printStackTrace();
        return ResponseResult.error(e.getMessage());
    }
}
